package mrdemo009;

import java.io.IOException;
import java.util.Arrays;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class FlowMap extends Mapper<LongWritable, Text, Text, FlowBean> {

	@Override
	protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, FlowBean>.Context context)
			throws IOException, InterruptedException {

		// 1 获取一行
		String line = value.toString();
		// 2 切割字段
		String[] fields = line.split("\t");
		// 3 封装对象
		// 取出手机号码
		String phoneNum = fields[1];
		// 取出上行流量和下行流量
		long upFlow = Long.parseLong(fields[fields.length - 3]); //倒数第3索引值为长度减3
		long downFlow = Long.parseLong(fields[fields.length - 2]);//倒数第2索引值为长度减2
		// 4 写出
		context.write(new Text(phoneNum), new FlowBean(upFlow, downFlow));
	}
	 

}
